<?php
	/**
	 * 商品列表页控制器
	 */
	class GoodslistAction extends Action{
		//商品列表首页
		public function index(){
			if($this->_get('cid')){
				$cid = $this->_get('cid' , 'intval');
				// 商品与商品分类视图模型
				$db = D('GoodsList');
				// 判断用户访问的是否是哪个级别的分类
				$result = M('category')->select();
				// 传递分类id检索其所有的子id
				$allChildsCate = recursion($result , $cid , 4);
				if(count($allChildsCate) == 0){//末级分类
					$goodsListCont = $db->where('goods.cid=' . $cid)->select();
					$this->goodsListCont = $goodsListCont; //分类分类下的商品到商品列表展示
				}else if(count($allChildsCate) > 0){//非末级分类
					$allChildsCateId = array();
					foreach($allChildsCate as $key => $val){
						$allChildsCateId[$key] = $val['id'];
					}
					$goodsListCont = $db->where(array('goods.cid' => array('IN' , $allChildsCateId)))->select();
					$this->goodsListCont = $goodsListCont; //分类分类下的商品到商品列表展示
				}
				//当前所在位置使用等级栏目
				$parentCates = recursion(M('category')->select() , $cid , 2);
				$this->parentCates = $parentCates;
			}
			$this->display();
		}
	}
?>